'''
Created on 2010-3-3

@author: Administrator
'''
import sys
import math
from jolly.datastructures.Object import Object

class Float(float, Object):
    '''
    Float class.
    '''


    def __init__(self,obj):
        '''
        (Float, object) -> None
        Constructs a string with the string representation of the given object.
        The Object metaclass provides a __new__ method
        that initializes the str instance, so none is defined here.
        '''
        pass
    
    def _compareTo(self, obj):
        '''
        (Float, Float) -> float

        Compares this string with the given string.
        '''
        assert isinstance(self, obj.__class__)
        return cmp(float(self), float(obj))
    
    def __hash__(self):
        '''
        (Float) -> float
        Hashes this string.
        '''
        (m, e) = math.frexp(self)
        mprime = int((abs(m)-0.5)*(1L<<52))
        return mprime>>20
    
    @staticmethod
    def testHash():
        "Float hash test program."
        print Float.testHash.__doc__
        print "57.=0%o" % hash(Float(57.))
        print "23.=0%o" % hash(Float(23.))
        print "0.75=0%o" % hash(Float(0.75))
        print "-123.e6=0%o" % hash(Float(-123.e6))
        print "-123.e7=0%o" % hash(Float(-123.e7))
        print "0.875=0%o" % hash(Float(0.875))
        print "14.=0%o" % hash(Float(14.))
    
    @staticmethod
    def main(*argv):  
        "Float test program."
        print Float.main.__doc__
        Float.testHash()
        return 0

if __name__=="__main__":
    sys.exit(Float.main(*sys.argv))